import { JupiterArticle, JupiterArticleQuery } from '../types/articleTypes';
import request from 'utils/request';

// 获取文章列表
export const fetchArticleList = (params: JupiterArticleQuery) => {
  return request.post('/articles/page', params);
};

// 获取所有文章
export const fetchAllArticles = () => {
  return request.get('/articles');
};

// 根据UUID获取文章
export const fetchArticleById = (uuid: string) => {
  return request.get(`/articles/${uuid}`);
};

// 创建文章
export const createArticle = (data: Partial<JupiterArticle>) => {
  return request.post('/articles', data);
};

// 更新文章
export const updateArticle = (uuid: string, data: Partial<JupiterArticle>) => {
  return request.put(`/articles/${uuid}`, data);
};

// 删除文章
export const deleteArticle = (uuid: string) => {
  return request.delete(`/articles/${uuid}`);
};

// 批量删除文章
export const batchDeleteArticles = (uuids: string[]) => {
  return request.delete('/articles/batch', { data: { uuids } });
};

// 发布文章
export const publishArticle = (uuid: string) => {
  return request.put(`/articles/${uuid}/publish`);
};

// 归档文章
export const archiveArticle = (uuid: string) => {
  return request.put(`/articles/${uuid}/archive`);
};

// 置顶文章
export const topArticle = (uuid: string, isTop: boolean) => {
  return request.put(`/articles/${uuid}/top`, { isTop });
};

// 增加浏览量
export const incrementViewCount = (uuid: string) => {
  return request.put(`/articles/${uuid}/view`);
};

// 根据分类获取文章列表
export const fetchArticlesByCategory = (categoryUuid: string, params?: { page: number; size: number }) => {
  return request.get(`/articles/category/${categoryUuid}`, { params });
};

// 根据标签获取文章列表
export const fetchArticlesByTag = (tagUuid: string, params?: { page: number; size: number }) => {
  return request.get(`/articles/tag/${tagUuid}`, { params });
};

// 获取热门文章
export const fetchPopularArticles = (limit: number = 10) => {
  return request.get(`/articles/popular?limit=${limit}`);
};

// 获取最新文章
export const fetchLatestArticles = (limit: number = 10) => {
  return request.get(`/articles/latest?limit=${limit}`);
};
